package com.hxgis.common.dto;

import com.hxgis.common.entity.RainstormInfo;
import com.hxgis.common.utils.NumUtil;
import com.hxgis.common.utils.TimeUtil;

import java.util.List;

/**
 * @author cqj
 * @version 1.0
 * @date 2019/9/26 10:20
 */
public class GroupAreaTargetDTO {
    //开始时间
    private Long startTime;
    //结束时间
    private Long endTime;
    //持续时间
    private Integer continueDays;
    //平均强度
    private double avgStrength;
    //平均影响范围
    private double getAffectArea;
    //综合强度指标
    private double compositeIndex;
    //组过程标识
    private String groupAreaFlag;

    private List<RainstormInfo> rainstormInfos;


    public GroupAreaTargetDTO(List<RainstormInfo> rainstormInfos) {
        this.rainstormInfos = rainstormInfos;
        rainstormInfos.sort((o1, o2) -> {
            return (int) (o1.getTime()-o2.getTime());
        });
        startTime = rainstormInfos.get(0).getTime();
        endTime = rainstormInfos.get(rainstormInfos.size()-1).getTime();
        continueDays = TimeUtil.getDaysBetween2Date(String.valueOf(startTime), String.valueOf(endTime));
        groupAreaFlag = groupAreaFlag = rainstormInfos.get(0).getCourseContinue();
        //总降水量
        double sumRainFall = rainstormInfos.stream().mapToDouble(RainstormInfo::getRainFall).sum() / 10;
        avgStrength = NumUtil.save2Point(sumRainFall/(continueDays * rainstormInfos.size()));
        getAffectArea = NumUtil.save2Point(rainstormInfos.size() / continueDays);
        compositeIndex = NumUtil.save2Point(    avgStrength * Math.sqrt(continueDays) * Math.sqrt(getAffectArea));
    }




    public Long getStartTime() {
        return startTime;
    }

    public void setStartTime(Long startTime) {
        this.startTime = startTime;
    }

    public Long getEndTime() {
        return endTime;
    }

    public void setEndTime(Long endTime) {
        this.endTime = endTime;
    }

    public Integer getContinueDays() {
        return continueDays;
    }

    public void setContinueDays(Integer continueDays) {
        this.continueDays = continueDays;
    }

    public double getAvgStrength() {
        return avgStrength;
    }

    public void setAvgStrength(double avgStrength) {
        this.avgStrength = avgStrength;
    }

    public double getGetAffectArea() {
        return getAffectArea;
    }

    public void setGetAffectArea(double getAffectArea) {
        this.getAffectArea = getAffectArea;
    }

    public double getCompositeIndex() {
        return compositeIndex;
    }

    public void setCompositeIndex(double compositeIndex) {
        this.compositeIndex = compositeIndex;
    }

    public List<RainstormInfo> getRainstormInfos() {
        return rainstormInfos;
    }

    public void setRainstormInfos(List<RainstormInfo> rainstormInfos) {
        this.rainstormInfos = rainstormInfos;
    }

    public String getGroupAreaFlag() {
        return groupAreaFlag;
    }

    public void setGroupAreaFlag(String groupAreaFlag) {
        this.groupAreaFlag = groupAreaFlag;
    }

    @Override
    public String toString() {
        return "GroupAreaTargetDTO{" +
                "startTime=" + startTime +
                ", endTime=" + endTime +
                ", continueDays=" + continueDays +
                ", avgStrength=" + avgStrength +
                ", getAffectArea=" + getAffectArea +
                ", compositeIndex=" + compositeIndex +
                ", groupAreaFlag='" + groupAreaFlag + '\'' +
                ", rainstormInfos=" + rainstormInfos +
                '}';
    }
}
